package com.qingchunlin.springprinciple.component;

import com.qingchunlin.springprinciple.entity.User;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

@Component
public class BeanLifeComponent implements BeanNameAware, BeanPostProcessor {
    private User user;

    BeanLifeComponent() {
        System.out.println("执行构造函数");
    }

    @Resource(name = "user1")
    public void setUser(User user) {
        this.user = user;
        System.out.println("属性注入");
    }

    @PostConstruct
    public void init1() {
        System.out.println("执行初始化方法");
    }

    public void use() {
        System.out.println("执行use方法");
    }

    @PreDestroy
    public void destroy1() {
        System.out.println("执行destroy方法");
    }

    @Override
    public void setBeanName(String name) {
        System.out.println("执行beanNameAware,name: " + name);
    }
}
